<template>
	<view>

		<view class="confirm-order">
			<view class="confirm-con">
				<!-- 地址 -->
				<view class="adressView">
					<!-- <view class="adressView1 " :class="[tabCurrent?'adressView2':'']">
						<u-tabs bg-color="#fffff00" :list="tabs" :is-scroll="false" :current="tabCurrent" font-size="28"
							active-color="#65BEFF" bar-width="80" :bar-style="{'background-color': '#65BEFF'}"
							@change="changeTab" />
					</view> -->
					<!-- 地址 -->
					<navigator v-if="!tabCurrent" hover-class="none" url="/pages/user_address/user_address?type=1">
						<address-item :address="address" />
					</navigator>
					<view v-if="tabCurrent" class="adressView3">
						<view @click="daohang()" class="flex-row-space-between">
							<view class="adressView3Title flex1">
								{{shopInfo.city}}{{shopInfo.op_area}}
							</view>
							<!-- <image class="adressView3Image" src="/static/lease/address2.png" mode="aspectFill"></image> -->

						</view>
						<view class="flex-row-flex-start">

							<view class="" style="width: 50%;padding-left: 20rpx;">
								<uni-datetime-picker type="datetime" :value="pick_up_time" hide-second @change="change">
									<!-- 	<picker mode="date" fields="day" :value="pick_up_time"  @change="bindDateChange"> -->
									<view class="flex-row-flex-start">
										<view class="adressView3Title1">
											自取时间
										</view>
										<u-icon name="arrow-right" size="16" color="#666666"></u-icon>
									</view>
									<view class="time">
										{{pick_up_time}}
									</view>
								</uni-datetime-picker>
								<!-- </picker> -->
							</view>



							<view class="" style="width: 50%;padding-left: 20rpx;">
								<view class="flex-row-flex-start">
									<view class="adressView3Title1">
										预留电话
									</view>
									<image src="/static/common/edit.png" mode=""
										style="margin-left: 4px; width: 26rpx;height: 26rpx;"></image>
								</view>
								<view class="time">
									<input v-model="link_mobile" type="text" placeholder="请输入">
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- <navigator hover-class="none" url="/pages/user_address/user_address?type=1">
					<address-item :address="address" />
				</navigator> -->

				<!-- 商品信息 -->
				<view class="goods contain">
					<view @click="shopButtonClick()" class="flex-row-flex-start" style="margin-top: 30rpx;">
						<view class="store_name">
							{{ shopInfo.shop_name}}
						</view>
						<u-icon name="arrow-right" size="26" color="#000"></u-icon>
					</view>
					<view class="lease-goods">
						<lease-order-goods :image="goods.image">
							<template #name>{{ goods.goods_name }}</template>
							<template #specs>
								{{ goods.spec_value_str }}，
								{{ goods.periods }}{{ getPeriodsUnit(goods.periods_attribute) }}
							</template>
							<template #price>
								<price :content="goods.day_rent_price" mainSize="38rpx" minorSize="24rpx"
									color="#333333" :isPrefix="true" :isSuffix="true" v-if="goods.day_rent_price" />
								<text>（x{{ goods.periods }}期）</text>
							</template>
						</lease-order-goods>
					</view>

					<!-- <view class="item row-between">
						<view>配送方式</view>
						<view>快递</view>
					</view>
					<view class="item row-between">
						<view>买家留言</view>
						<u-input 
                          v-model="userRemark" 
                          class="flex1 ml20" 
                          :clearable="false" 
                          placeholder="请添加备注（150字以内）" 
                        />
					</view> -->
				</view>
				<view class="view1">
					<view class="itemView flex-row-space-between">
						<view class="leftTitle">
							首期应付费用
						</view>
						<view class="rightTitle">
							¥{{ orderInfo.first_return_price }}
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							租期
						</view>
						<view class="rightTitle1">
							{{ goods.periods }}期
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							每期应还
						</view>
						<view class="rightTitle1">
							¥{{ orderInfo.issue_rent }}
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							总租金
						</view>
						<view class="rightTitle1">
							¥{{ orderInfo.total_goods_rent}}
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							服务费
						</view>
						<view class="rightTitle1">
							¥{{ orderInfo.service_charge }}
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							设备管理费
						</view>
						<view class="rightTitle1">
							¥{{ orderInfo.equipment_management_fee }}
						</view>
					</view>
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							押金
						</view>
						<view class="rightTitle1">
							¥{{orderInfo.deposit}}
						</view>
					</view>
					<view v-if="Number(orderInfo.rent_type)==10" class="itemView flex-row-space-between">
						<view @click="markClick()" class="flex-row-flex-start">
							<view class="leftTitle1">
								买断价
							</view>
							<image class="mark" src="/static/common/mark.png" mode="scaleToFill"></image>
						</view>

						<view class="rightTitle1">
							¥{{orderInfo.buyout_price}}
						</view>
					</view>

					<view v-if='orderInfo.service.id' class="itemView flex-row-space-between">
						<view class="leftTitle1">
							{{orderInfo.service.s_name}}
						</view>
						<view class="rightTitle1">
							¥{{orderInfo.service.price}}
						</view>
					</view>

				</view>
				<view class="view1">
					<view class="itemView flex-row-space-between">
						<view class="leftTitle">
							账单明细
						</view>
					</view>
					<view v-for="(item1,index1) in orderInfo.periodization_date" :key="index1">
					<view class=" flex-row-space-between">
						<view class="">
							<view class="leftTitle1" >
								<text v-if="index1==1">预付金额</text>
								<text v-else>第{{item1.month-1}}期</text>
								
							</view>
							
							<view class="leftTitle1" style="margin-top: 10rpx; margin-bottom: 10rpx;">
								{{item1.repayment_times}}
							</view>
						</view>
						<view class="rightTitle1">
							¥{{item1.amount_payable}}
						</view>
						
					</view>
					</view>

				</view>
				<view class="view1">

					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							配送方式
						</view>
						<view class="rightTitle1">
							<text v-if="tabCurrent">自取</text>
							<text v-if="!tabCurrent">快递</text>
						</view>
					</view>
					<!-- 	<view class="itemView flex-row-space-between">
           		<view class="leftTitle1">
           			运费
           		</view>
           		<view class="rightTitle1">
           			¥{{orderInfo.shipping_price || '0.00'}}
           		</view>
           	</view> -->
				</view>

				<!-- <view class="view2 ">
				<view class="flex-row-space-between">
					<view class="flex-row-flex-start">
						<image class="hbImage" src="/static/image/hb.png" mode="aspectFill"></image>
						<view class="hbTitle">
							芝麻信用·免押金
						</view>
					</view>
					<view class="">
						<text class="hbTitle2">押金</text>
						<text class="hbTitle1">￥9999</text>
					</view>
				</view>
				<view class="hbTitle3">
					芝麻分699免押金
				</view>
		   </view> -->

				<view class="view1">
					<view class="itemView flex-row-space-between">
						<view class="leftTitle1">
							备注
						</view>
						<!-- <view class="rightTitle1"> -->
						<input class="rightTitle1" style="text-align: right;" v-model="userRemark" placeholder="请输入备注"
							type="text">
						<!-- </view> -->
					</view>
				</view>

		
		<view class="view1">
			<view class="itemView flex-row-space-between">
				<view class="leftTitle">
					紧急联系人
					<text class="" style="color: red;">*</text>
				</view>
		
			</view>
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					姓名
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_one_name"
					placeholder="请输入姓名" type="text">
			</view>

				<view class="itemView flex-row-space-between">
					<view class="leftTitle1">
						关系
					</view>
					<input class="rightTitle1" style="text-align: right;" v-model="mobile_one_relation"
						placeholder="请输入关系" type="text">
				</view>
	
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					手机号
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_one" placeholder="请输入手机号"
					type="number">
			</view>
		</view>
		<view class="view1">
			<view class="itemView flex-row-space-between">
				<view class="leftTitle">
					紧急联系人1
					<!-- <text class="" style="color: red;">*</text> -->
				</view>
		
			</view>
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					姓名
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_two_name"
					placeholder="请输入姓名" type="text">
			</view>

				<view class="itemView flex-row-space-between">
					<view class="leftTitle1">
						关系
					</view>
					<input class="rightTitle1" style="text-align: right;" v-model="mobile_two_relation"
						placeholder="请输入关系" type="text">
				</view>

		
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					手机号
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_two" placeholder="请输入手机号"
					type="number">
			</view>
		</view>
		
		<view class="view1">
			<view class="itemView flex-row-space-between">
				<view class="leftTitle">
					紧急联系人2
					<!-- <text class="" style="color: red;">*</text> -->
				</view>
		
			</view>
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					姓名
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_three_name"
					placeholder="请输入姓名" type="text">
			</view>
		
				<view class="itemView flex-row-space-between">
					<view class="leftTitle1">
						关系
					</view>
					<input class="rightTitle1" style="text-align: right;" v-model="mobile_three_relation"
						placeholder="请输入关系" type="text">
				</view>
		
			<view class="itemView flex-row-space-between">
				<view class="leftTitle1">
					手机号
				</view>
				<input class="rightTitle1" style="text-align: right;" v-model="mobile_three"
					placeholder="请输入手机号" type="number">
			</view>
		</view>

				<!-- 支付方式 -->
				<view class="pay-way contain">
					<view class="lighter title">支付方式</view>
					<radio-group class="radio-group" @change="radioChange">
						<label v-for="(item, index) in payWayArr" :key="index" class="item row-between">
							<view class="row">
								<image class="icon-lg mr20" :src="item.icon" />
								<view class>
									<view class="balck bt10">{{item.name}}</view>
									<view class="muted xs">{{item.extra}}</view>
								</view>
							</view>
							<radio color='#FF4D40' class="radio" :value="String(item.pay_way)"
								:checked="item.pay_way == payWay" />
						</label>
					</radio-group>
				</view>

			</view>

			<!-- 订单结算 -->
			<view class="footer bg-white fixed" style="width: 100%;">
				<u-checkbox-group>
					<u-checkbox v-model="isAgreeProtocol" shape="circle">
						<view class="sm row">
							<view class="lighter">已阅读并同意协议</view>
							<view class="primary" @tap.stop="showLeaseProtocol = true">《租赁协议》</view>
						</view>
					</u-checkbox>
				</u-checkbox-group>
				<view class="flex-row-space-between" style="padding: 20rpx 0;margin-top: -10rpx;width: 96%;">
					<view class="flex1 first_pay_amount">
						¥{{orderInfo.order_amount}}
					</view>
					<!--isQian=true onSubmitOrder -->
					<view @click="onSubmitOrder" class="bottomButton1 flex-column-center">
						去免押
					</view>
					<!-- <view class="all-price lg row">
						
						<view class="ornament">
					        <price 
					          :content="(goods.first_pay_amount)" 
					          mainSize="38rpx" 
					          minorSize="30rpx" 
					          :isSuffix="false" 
					          :isPrefix="true"
					        />
						</view>
					</view>
					<button
					  class="btn br60 white" 
					  size="md" 
					  hover-class="none" 
					  @tap="isQian=true"
					>
						提交订单
					</button> -->
					<!-- <button 
					  class="btn br60 white" 
					  size="md" 
					  hover-class="none" 
					  @tap="onSubmitOrder"
					>
						提交订单
					</button> -->
				</view>
			</view>
		</view>

		<loading-view v-if="showLoading" background-color="transparent" :size="50" />
		<loading-view v-if="isFirstLoading" />


		<!-- 租赁用户协议 -->
		<u-popup v-model="showLeaseProtocol" mode="center" border-radius="20">
			<view class="protocol">
				<view class="protocol-title">租赁用户协议</view>
				<scroll-view scroll-y="true" class="protocol-content">
					<u-parse :html="protocolHtml" />
				</scroll-view>
				<view class="protocol-confirm" @tap="showLeaseProtocol = false">我知道了</view>
			</view>
		</u-popup>

		<u-popup v-model="popupShow" mode="center" border-radius="14">
			<view class="popupView flex-column-center" v-show="popupShow">
				<view class="popupTitle">
					买断价
				</view>
				<view class="popupTitle1">
					租赁到期后，如果您选择买断，一次性支付买断金额后，即可终身拥有此商品。
				</view>
			</view>
			<view class="flex-column-center">
				<image @click="markClick1()" class="closeImage" src="/static/common/close.png" mode="scaleToFill">
				</image>
			</view>

		</u-popup>

		<!-- 支付密码 -->
		<set-pay-pwd ref="setPayPwd" @confirm="orderBuyFun" />
	</view>
</template>

<script>
	import {
		prepay,
		orderFreeze,
		getMnpNotice,
		getAlipayPayStatus
	} from '@/api/app';

	import {
		wxpay,
		alipay
	} from '@/utils/pay'
	import {
		getUserInfo,
		setUserInfo,
	} from "@/api/user";
	import {
		payment,
		leaseBuy,
		getLeaseProtocol,
		getShopInfo
	} from '@/api/lease.js'
	// import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
	import {
		getOrderCoupon
	} from '@/api/order';

	export default {
		data() {
			return {
				mobile_one: "",
				mobile_two: "",
				mobile_three: "",
				mobile_one_name: "",
				mobile_two_name: "",
				mobile_three_name: "",
				mobile_one_relation: "",
				mobile_two_relation: "",
				mobile_three_relation: "",
				popupShow: false,
				tabCurrent: 0,
				link_mobile: '',
				pick_up_time: '',
				// Tabs列表
				tabs: [{
						key: '快递配送',
						name: '快递配送'
					},
					// {
					// 	key: '到点自取',
					// 	name: '到点自取'
					// },

				],
				shopInfo: {},
				userInfo: {},
				isQian: false,

				isFirstLoading: false && true,
				showLoading: false,
				address: {}, // 当前地址信息
				orderInfo: {}, // 订单信息
				goods: {}, // 商品数据
				addressId: '', // 所选地址ID
				userRemark: '', // 留言

				popActive: 0, // 优惠券Tabs当前索引

				payWayArr: [], // 支付方式列表
				payWay: '', // 所选的支付方式

				payload: null, // 已选规格
				isAgreeProtocol: false, // 协议是否同意
				showLeaseProtocol: false, // 协议 Popup
				protocolHtml: '', // 富文本协议内容
			};
		},
		comments: {
			// uniDatetimePicker
		},
		computed: {

			// 每天多少钱
			oneDayPrice() {
				// const unit = this.goods.periods_attribute;
				// const issueRent = this.goods.issue_rent;
				// switch(unit) {
				// 	case 'is_week': 
				// 		return Number((issueRent / 7).toString().match(/^\d+(?:\.\d{0,2})?/));
				// 	case 'is_month': 
				// 		return Number((issueRent / 30).toString().match(/^\d+(?:\.\d{0,2})?/));
				// }
			},
		},

		methods: {
			markClick() {
				this.popupShow = true
			},
			markClick1() {
				this.popupShow = false
			},
			//时间选择
			bindDateChange(e) {
				console.log(e)
				this.pick_up_time = e.detail.value
			},
			change(e) {
				this.pick_up_time = e

			},
			// 切换Tabs
			changeTab(index) {

				this.tabCurrent = index;
			},

			shopButtonClick() {
				var shop_id = uni.getStorageSync('shop_id') ? uni.getStorageSync('shop_id') : 1
				uni.navigateTo({
					url: '/bundle/pages/lease_goods_details/shop?shop_id=' + shop_id
				})
			},

			// 输出分期单位
			getPeriodsUnit(value) {
				return '期'
				// switch(value) {
				//     case 'is_week': return '周';
				//     case 'is_month': return '个月';
				// }
			},

			// 选择支付方式
			radioChange(e) {
				const value = e.detail.value;
				this.payWay = value * 1;
			},

			// 微信
			getAuthMsg() {
				return new Promise(resolve => {
					getMnpNotice({
						scene: 1
					}).then(res => {
						if (res.code == 1) {
							const data = res.data;
							uni.requestSubscribeMessage({
								tmplIds: data
							});
						}
						resolve();
					});
				});
			},
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			// 点击下单
			onSubmitOrder() {
				if (this.tabCurrent) {
					if (!this.pick_up_time.length) {
						this.showToast('请选择自取时间')
						return
					}
					if (!this.link_mobile.length) {
						this.showToast('请输入预留电话')
						return
					}
				} else {
					if (!Number(this.addressId)) {
						this.showToast('请选择地址')
						return
					}
				}
				if (!this.mobile_one_name.length) {
					this.showToast('请输入紧急联系人姓名')
					return
				}
				if (!this.mobile_one_relation.length) {
					this.showToast('请输入紧急联系人关系')
					return
				}
				if (!this.mobile_one.length) {
					this.showToast('请输入紧急联系人手机号')
					return
				}
				if (!this.isAgreeProtocol)
					return uni.showToast({
						title: '请先阅读并同意协议',
						icon: 'none'
					});
					// const submitObj = {
					// 	one_mobile:this.mobile_one,
					// 	two_mobile:this.mobile_two,
					// 	three_mobile:this.mobile_three,
						
					// 	one_name: this.mobile_one_name,
					// 	two_name:this.mobile_two_name,
					// 	three_name:this.mobile_three_name,
					// 	one_relation: this.mobile_one_relation,
					// 	two_relation: this.mobile_two_relation,
					// 	three_relation: this.mobile_three_relation,
						
						
					// };
					// console.log(submitObj)
					// return
				// if (!this.addressId)
				//   return uni.showToast({ title: '请选择收货地址', icon: 'none' });

				uni.showModal({
					title: '温馨提示',
					content: '是否确认下单?',
					confirmColor: '#FF2C3C',
					success: async res => {
						if (!res.confirm) return;

						// #ifdef MP-WEIXIN
						await this.getAuthMsg();
						// #endif

						// if (this.payWay == 3) {
						// 	this.$refs.setPayPwd.hasPayWord().then(res => {
						// 		this.$refs.setPayPwd.showInputPwd();
						// 	});
						// } else {
						this.orderBuyFun1();
						// }
					}
				});
			},
			orderBuyFun1() {
				this.showLoading = true;
				// if(!this.payWayArr.length) {
				//     this.showLoading = false;
				//     return this.$toast({ title: '请联系管理员配置支付方式' });
				// }
				
				const address = this.address;
				const goods = this.goods;
				
			
				if (this.userInfo.mobile.length) {
					if (Number(this.userInfo.is_auth)) {
						this.orderBuyFun()
					} else {
						uni.showModal({
							title: '温馨提示',
							content: '您未实名认证,请认证?',
							confirmColor: '#FF2C3C',
							success: async res => {
								if (!res.confirm) return;
								uni.navigateTo({
									url: "/pages/user/realName"
								})
							}
						});
					}
				} else {
					uni.showModal({
						title: '温馨提示',
						content: '您暂未绑定手机号，请先绑定?',
						confirmColor: '#FF2C3C',
						success: async res => {
							if (!res.confirm) return;
							uni.navigateTo({
								url: '/bundle/pages/user_profile/user_profile'
							})

						}
					});
				}


			},

			orderFreeze(order_id, data) {
				console.log(order_id)
				orderFreeze({
					order_id: order_id
				}).then(res => {
					console.log('orderFreeze', res)
					if (res.code == 1) {
						this.tradePay(res.data.content, order_id, data)
					}
				});
			},
			tradePay(orderStr, order_id, data) {
				var that = this
				my.tradePay({
					// 调用资金冻结接口（alipay.fund.auth.order.app.freeze），获取资金授权参数
					orderStr: orderStr,
					success: (result) => {
						console.log('success', result)
						if (Number(result.resultCode) == 9000) {

							setTimeout(function() {
								that.payAliPay(data, order_id);
							}, 1000);

						} else {
							that.showToast('支付失败')
						}
					},
					fail: (result) => {
						console.log('success', result)
					}
				});
			},
			// 下单处理
			orderBuyFun(password) {
				console.log('orderBuyFun-----------');

				this.showLoading = true;
				// if(!this.payWayArr.length) {
				//     this.showLoading = false;
				//     return this.$toast({ title: '请联系管理员配置支付方式' });
				// }

				const address = this.address;
				const goods = this.goods;

				const submitObj = {
					one_mobile:this.mobile_one,
					two_mobile:this.mobile_two,
					three_mobile:this.mobile_three,
					
					one_name: this.mobile_one_name,
					two_name:this.mobile_two_name,
					three_name:this.mobile_three_name,
					
					one_relation: this.mobile_one_relation,
					two_relation: this.mobile_two_relation,
					three_relation: this.mobile_three_relation,
					
					
					delivery_type: this.tabCurrent ? '2' : '1',
					pick_up_time: this.pick_up_time,
					link_mobile: this.link_mobile,
					// rent_type:this.payload.goods[0].rent_type,
					service_id: this.payload.goods[0].service_id,
					action: 'submit',
					type: 'buy_now',
					goods: [{
						lease_goods_id: goods.id,
						item_id: goods.item_id,
						goods_num: goods.goods_num,
						periods_id: goods.periods_id,
						remark: this.userRemark
					}],
					insurance: goods.insurance,
					pay_way: this.payWay,
					// pay_way: 2,
					address_id: this.addressId,
					pay_password: password,
					shop_id: uni.getStorageSync('shop_id') ? uni.getStorageSync('shop_id') : 1
				};



				console.log('submitObj',submitObj);

				leaseBuy(submitObj).then(res => {

					console.log('in------leaseBuy');
					console.log(res);



					const data = res.data;
					const code = res.code;
					const order_id = data.order_id;
					const type = data.from;
					this.showLoading = false;

					console.log('leaseBuy-sucess----------type:' + type);
					const isOfflien = data.isOffline;
					if (isOfflien === true) {
						uni.redirectTo({
							url: '/bundle/pages/lease_pay_result/lease_pay_result' +
								'?id=' + order_id
						});
						return;
					}
					var that = this
					prepay({
						from: type,
						order_id: order_id
					}).then(({
						code,
						data
					}) => {
						switch (code) {
							// 微信支付
							case 1:
								that.payWeChat(data, order_id);
								break;
								// 支付宝支付
							case 20001:
								that.orderFreeze(order_id, data)

								// that.payAliPay(data, order_id);
								break;
								// 余额支付
							case 10001:
								uni.redirectTo({
									url: '/bundle/pages/lease_pay_result/lease_pay_result' +
										'?id=' + order_id
								});
								break;
						}
					}).catch(err => {
						that.$toast({
							title: '支付失败，请重试'
						});
						console.log(err);
					});
					// orderFreeze({
					// 	order_id: order_id
					// }).then((res) => {
					// 		my.tradePay({
					// 		  // 调用资金冻结接口（alipay.fund.auth.order.app.freeze），获取资金授权参数
					// 		  orderStr: res.data.content,
					// 		  success: (result) => {
					// 			  var that = this
					// 			  console.log(result)
					// 				console.log(res.data.trade_no)
					// 				if(result.resultCode == 9000){
					// 					setTimeout(function() {
					// 						// that.payAction(res.data.trade_no)





					// 					}, 1000);
					// 				}
					// 		  },
					// 		  fail: (result) => {
					// 			  console.log(result)
					// 		  }
					// 		});
					// }).catch(err => {
					// 		this.$toast({ title: '支付失败，请重试' });
					// 		console.log(err);				
					// });

					// return




				});
			},

			bottomButtonClick() {

				orderHire({
					goods_id: this.data.id,
					shop_id: this.shop_id,
					num: this.number
				}).then(res => {
					if (res.code == 1) {
						my.tradePay({
							// 调用资金冻结接口（alipay.fund.auth.order.app.freeze），获取资金授权参数
							orderStr: res.data.url,
							success: (result) => {
								var that = this
								console.log(result)
								console.log(res.data.trade_no)
								if (result.resultCode == 9000) {
									setTimeout(function() {
										that.payAction(res.data.trade_no)
									}, 1000);
								}
							},
							fail: (result) => {
								console.log(result)
							}
						});

						// uni.showToast({
						// 	title:'租借成功',
						// 	icon:'success'
						// })
					} else if (res.code == 10) {

						uni.showModal({
							title: '提示',
							content: res.msg,
							success: (res) => {
								uni.navigateTo({
									url: '/pages/lease/certify'
								})
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					console.log(error)
					if (error.statusCode == 1001) {
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}
				})

			},

			// 微信支付
			payWeChat(data, orderID) {
				wxpay(data).then(res => {
					if (res == 'success') {
						uni.redirectTo({
							url: '/bundle/pages/lease_pay_result/lease_pay_result' +
								'?id=' + orderID
						});
					} else {
						uni.redirectTo({
							url: '/bundle/pages/lease_order_detail/lease_order_detail' +
								'?id=' + orderID
						});
					}
				})
			},

			// 支付宝支付
			payAliPay(data, orderID) {

				console.log('payAliPay------start');

				// #ifdef H5 || APP-PLUS
				alipay(data);
				// #endif

				// #ifdef MP-ALIPAY
				const tradeNo = data?.data?.trade_no;
				my.tradePay({
					// 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号trade_no
					tradeNO: tradeNo,
					success: (res) => {
						getAlipayPayStatus({
							trade_no: tradeNo
						}).then(res => {
							if (res.tradeStatus == 'TRADE_SUCCESS') {
								uni.redirectTo({
									url: '/bundle/pages/lease_pay_result/lease_pay_result' +
										'?id=' + orderID
								});
							} else {
								uni.redirectTo({
									url: '/bundle/pages/lease_order_detail/lease_order_detail' +
										'?id=' + orderID
								});
							}
						});
					},
					fail: (res) => {
						uni.redirectTo({
							url: '/bundle/pages/lease_order_detail/lease_order_detail' +
								'?id=' + orderID
						});
					}
				});
				// #endif
			},
			$getUserInfo() {
				getUserInfo().then(res => {
					if (res.code == 1) {
						this.userInfo = res.data;

					}
				});
			},
			getShopInfo() {
				getShopInfo({
					shop_id: uni.getStorageSync('shop_id') ? uni.getStorageSync('shop_id') : 1
				}).then(({
					code,
					data
				}) => {
					if (code != 1) return;
					this.shopInfo = data
				});
			},

		},


		onLoad(options) {
			const data = JSON.parse(decodeURIComponent(options.data));
			this.payload = data;
			this.getShopInfo()
			// 选择地址
			uni.$on("selectaddress", e => {
				const id = e.id;
				const address = e.address;

				this.addressId = e.id
				this.address = address;
			});

			// 获取付款方式
			payment().then(res => {
				if (res.code != 1) return;
				const data = res.data;
				this.payWayArr = data;
				this.payWay = data.length ? data[0].pay_way : 0
			});

			// 获取协议内容
			getLeaseProtocol().then(res => {
				console.log(res);
				if (res.code != 1) return;
				this.protocolHtml = res.data || '';
			});
		},

		onShow() {
			const data = this.payload;
			var params = {

				...data,
				service_id: data.goods[0].service_id,
				address_id: this.addressId,
				action: 'info',
				type: 'buy_now'

			}
			console.log(params)
			leaseBuy(params).then(res => {
				if (res.code != 1) return;
				const data = res.data;
				this.orderInfo = data;
				this.address = data.address;
				this.addressId = data?.address?.id || '';
				this.goods = data.goods_lists[0];

			});
			this.$getUserInfo()
		},

		onUnload() {
			uni.$off("selectaddress");
		},

	}
</script>
<style>
	.confirm-order .confirm-con {
		overflow: hidden;
		padding-bottom: calc(186rpx + 20rpx + env(safe-area-inset-bottom));
	}

	.confirm-order .contain {
		border-radius: 14rpx;
		margin: 20rpx 20rpx 0;
		background-color: #fff;
		overflow: hidden;
	}

	.confirm-order .img-line {
		height: 1.5px;
		width: 100%;
		display: block;
	}


	.confirm-order .coupons {
		height: 100rpx;
		padding: 0 24rpx;
	}

	.goods .title {
		padding: 22rpx 24rpx;
		border-bottom: 1px solid #F6F6F6;
	}

	.goods .all-num {
		padding: 22rpx 24rpx;
		border-bottom: 1px dotted #F6F6F6;
	}

	.lease-goods {
		padding: 24rpx 20rpx;
	}

	.confirm-order .footer {
		box-sizing: content-box;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		/* height: 126rpx; */
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 20rpx;
		padding-bottom: env(safe-area-inset-bottom);
	}


	.confirm-order .pay-way .title {
		padding: 20rpx 24rpx;
	}

	.confirm-order .pay-way .radio-group .item {
		height: 120rpx;
		padding: 0 24rpx;
	}

	.confirm-order .price {
		padding: 28rpx 20rpx;
	}

	.confirm-order .price .item:not(:last-of-type) {
		margin-bottom: 20rpx;
	}

	.confirm-order .goods>.item,
	.confirm-order .benefit>.item {
		padding: 0 24rpx;
		height: 80rpx;
	}

	.confirm-order .btn {
		background-color: #FF4D40;
		padding: 0 50rpx;
	}

	.confirm-order .van-cell:after {
		border: none;
	}

	.goods .shop-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.pop-title {
		height: 100rpx;
		border-bottom: 1rpx solid #F2F2F2;
	}

	.pop-title .title {
		margin-left: 30rpx;
		font-size: 34rpx;
		font-weight: bold;
		line-height: 36rpx;
	}

	.periods-price {
		padding: 0 20rpx;
	}

	.periods-price-item {
		padding: 20rpx 0;
	}

	.periods-price-item:nth-child(n + 2) {
		border-top: 1px solid #E5E5E5;
	}

	.periods-price-title {
		padding: 10rpx 0;
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
	}

	.periods-price-row {
		padding: 10rpx 0;
		font-size: 26rpx;
	}


	.protocol {
		display: flex;
		flex-direction: column;
		width: 88vw;
		height: 88vh;
		padding: 20rpx;
		background-color: #FFFFFF;
	}

	.protocol-title {
		padding: 20rpx 0;
		font-size: 32rpx;
		font-weight: 500;
		text-align: center;
		color: #333333;
	}

	.protocol-content {
		flex: 1;
		overflow: scroll;
	}

	.protocol-confirm {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 72rpx;
		border-radius: 50px;
		margin-top: 20rpx;
		font-size: 32rpx;
		background-color: #FF4D40;
		color: #FFFFFF;
	}

	.item {
		width: 90%;
	}

	.view1 {
		margin: 20rpx;
		padding: 20rpx;
		background: #FFFFFF;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}

	.itemView {
		height: 70rpx;
	}

	.leftTitle {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.rightTitle {
		font-size: 27rpx;
		font-family: DIN-Medium, DIN;
		font-weight: 550;
		color: #333333;
	}

	.leftTitle1 {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.rightTitle1 {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.first_pay_amount {

		font-size: 31rpx;
		font-family: DIN-Medium, DIN;
		font-weight: 550;
		color: #FF5B5B;
	}

	.bottomButton1 {
		width: 336rpx;
		height: 69rpx;
		background: #FF4D40;
		border-radius: 38rpx 38rpx 38rpx 38rpx;
		opacity: 1;
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}

	.view2 {
		padding: 24rpx 20rpx;
		margin: 20rpx;
		height: 149rpx;
		background: linear-gradient(180deg, #E7F5FF 0%, #FFFFFF 100%);
		border-radius: 11rpx 11rpx 11rpx 11rpx;
		opacity: 1;
	}

	.hbImage {
		margin-right: 6rpx;
		width: 26rpx;
		height: 26rpx;
	}

	.hbTitle {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.hbTitle1 {
		font-size: 30rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.hbTitle2 {
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.hbTitle3 {
		margin-top: 20rpx;
		font-size: 25rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FF4D40;
	}

	.store_name {
		margin-left: 30rpx;
		/* margin-top: 30rpx; */
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #000000;
	}

	.adressView {
		margin: 20rpx;
		background: #FFFFFF;
		border-radius: 11rpx;
		opacity: 1;
		padding-bottom: 20rpx;
	}

	.adressView1 {
		height: 94rpx;
		background-image: url('../../../static/lease/address.png');
		background-size: 100% 100%;
	}

	.adressView2 {
		background-image: url('../../../static/lease/address1.png');

	}

	.adressView3 {
		margin-top: 20rpx;
	}

	.adressView3Image {
		width: 256rpx;
		height: 153rpx;
	}

	.adressView3Title {
		margin-left: 20rpx;
		font-size: 31rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.adressView3Title1 {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.time {
		margin-top: 10rpx;
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.store_name {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #000000;
	}

	.mark {
		margin-left: 6rpx;
		width: 24rpx;
		height: 24rpx;
	}

	.popupView {
		padding: 30rpx;
		width: 580rpx;
		border-radius: 30rpx;
		background-color: #fff;
	}

	.popupTitle {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.popupTitle1 {
		margin-top: 20rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 400;
		color: #666;
	}

	.closeImage {
		margin-top: 20rpx;
		width: 42rpx;
		height: 42rpx;
	}
	.view1 {
		margin: 20rpx;
		padding: 20rpx;
		background: #FFFFFF;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}
	
	.itemView {
		height: 70rpx;
	}
	
	.leftTitle {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}
	
	.rightTitle {
		font-size: 27rpx;
		font-family: DIN-Medium, DIN;
		font-weight: 550;
		color: #333333;
	}
	
	.leftTitle1 {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}
	
	.rightTitle1 {
		font-size: 27rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}
	
</style>